package cn.exrick.xboot.modules.workovertime.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.exrick.xboot.modules.workovertime.entity.HkOvertimeUser;
import cn.exrick.xboot.modules.workovertime.mapper.HkOvertimeUserMapper;
import cn.exrick.xboot.modules.workovertime.service.IHkOvertimeUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hml
 * @since 2023-08-31
 */
@Service
@Transactional
public class HkOvertimeUserServiceImpl extends ServiceImpl<HkOvertimeUserMapper, HkOvertimeUser> implements IHkOvertimeUserService {


    @Autowired
    private HkOvertimeUserMapper hkOvertimeUserMapper;

    @Override
    public IPage<HkOvertimeUser> selectPage(Page<HkOvertimeUser> page, HkOvertimeUser hkOvertimeUser) {
        QueryWrapper<HkOvertimeUser> query = Wrappers.query();
        QueryWrapper<HkOvertimeUser> entityWrapper = getEntityWrapper(query, hkOvertimeUser);
        return hkOvertimeUserMapper.selectPage(page, entityWrapper);
    }


    @Override
    public List<HkOvertimeUser> selectList(HkOvertimeUser hkOvertimeUser) {
        QueryWrapper<HkOvertimeUser> query = Wrappers.query();
        QueryWrapper<HkOvertimeUser> entityWrapper = getEntityWrapper(query, hkOvertimeUser);
        return hkOvertimeUserMapper.selectList(entityWrapper);
    }

    /**
     * 公共查询条件
     *
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<HkOvertimeUser> getEntityWrapper(QueryWrapper<HkOvertimeUser> entityWrapper, HkOvertimeUser hkOvertimeUser) {
        //条件拼接
        if (StringUtils.isNotBlank(hkOvertimeUser.getHontUserId())) {
            entityWrapper.like(HkOvertimeUser.HONT_USER_ID, hkOvertimeUser.getHontUserId());
        }
        if (StringUtils.isNotBlank(hkOvertimeUser.getNickName())) {
            entityWrapper.like(HkOvertimeUser.NICK_NAME, hkOvertimeUser.getNickName());
        }
        if (StringUtils.isNotBlank(hkOvertimeUser.getDepartmentId())) {
            entityWrapper.like(HkOvertimeUser.DEPARTMENT_ID, hkOvertimeUser.getDepartmentId());
        }
        if (StringUtils.isNotBlank(hkOvertimeUser.getDepartmentTitle())) {
            entityWrapper.like(HkOvertimeUser.DEPARTMENT_TITLE, hkOvertimeUser.getDepartmentTitle());
        }
        if (StringUtils.isNotBlank(hkOvertimeUser.getHkOvertimeId())) {
            entityWrapper.like(HkOvertimeUser.HK_OVERTIME_ID, hkOvertimeUser.getHkOvertimeId());
        }
        return entityWrapper;
    }
}
